﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using SieenaDashboard.Domain;
using System.Configuration;

namespace Dashboard.Controllers
{
    public class HomeController : Controller
    {
        private readonly ISDService service;

        public HomeController() 
        {
            var domain = ConfigurationManager.AppSettings["Sharepoint.Domain"];
            var user = ConfigurationManager.AppSettings["Sharepoint.User"];
            var password = ConfigurationManager.AppSettings["Sharepoint.Password"];
            var serviceRoot = ConfigurationManager.AppSettings["Sharepoint.ServiceRoot"];

            service = new SieenaDashboard.Domain.Service(domain, user, password, serviceRoot);
        }

        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public PartialViewResult Events() 
        {
            return PartialView(service.GetEvents());
        }
        
        public JsonResult LoadPeople()
        {
            return Json(service.GetPeople(), JsonRequestBehavior.AllowGet);
        }

        [HttpGet]
        public JsonResult LoadNotices()
        {
            return Json(service.GetNotices(), JsonRequestBehavior.AllowGet);
        }
    }
}
